package com.annotation.demo3;

import java.util.Arrays;

/**
 * @ClassName Student
 * @Description 学生有姓名，性别，爱好三个信息，定义一个注解，用于描述学生的爱好（有多个）和允许设置学生性别的值，
 * 如:男、man、male、1，性别不在范围内则抛出异常
 * 实现化一个学生对象，输出学生的姓名，性别，爱好信息。
 * @Author Kx
 * @Date 2025/3/28 15:30
 * @Version 1.0
 */
public class Student {
    private String name;
    @GenderValidation(sex={"男","man","male","1"})
    private String sex;
    @Hobbies(hobby={"打球","看电影","看小说"})
    private String[] hobby;

    public Student() {

    }
    public Student(String name, String sex, String[] hobby) {
        this.name = name;
        this.sex = sex;
        this.hobby = hobby;
        try {
            // 判断性别是否合法
            AnnotationProcessor.validateGender(this);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", hobby=" + Arrays.toString(hobby) +
                '}';
    }
}
